package com.yougou.data.repository;

import com.yougou.data.api.ApiService;
import com.yougou.data.api.RetrofitClient;
import com.yougou.data.model.response.CategoriesResponse;
import com.yougou.data.model.response.GoodsSearchResponse;

import io.reactivex.rxjava3.core.Observable;

public class CategoryRepository {
    
    private final ApiService mApiService;
    
    public CategoryRepository() {
        mApiService = RetrofitClient.createService(ApiService.class);
    }
    
    
    public Observable<CategoriesResponse> getCategories() {
        return mApiService.getCategories();
    }
    
    
    public Observable<GoodsSearchResponse> searchGoodsByCategory(int categoryId, int page, int pageSize) {
        Integer cid = categoryId > 0 ? categoryId : null;
        return mApiService.searchGoods(null, cid, page, pageSize);
    }
    
    
    public Observable<GoodsSearchResponse> searchGoods(String keyword, int page, int pageSize) {
        return mApiService.searchGoods(keyword, null, page, pageSize);
    }
}

